/*
 * @Author: fishroom
 * @Date: 2022-04-02 14:19:10
 * @LastEditTime: 2022-04-02 14:25:52
 * @FilePath: \website\src\utils\store.js
 */
/***
 * 用于导入多个store.state的值
 * ! mapper: 一个数组或对象
 */
import { computed } from "vue";
import { mapState, useStore } from "vuex";
export default function useState(mapper) {
  // 获取到store
  const store = useStore();
  // 通过mapState解析
  const storeStateFns = mapState(mapper);
  const storeState = {};
  // 对数据进行转换
  Object.keys(storeStateFns).forEach((fnKey) => {
    const fn = storeStateFns[fnKey].bind({ $store: store });
    storeState[fnKey] = computed(fn);
  });
  return storeState;
}
